import React from 'react'
import {
  Route, Switch, Redirect, withRouter,
} from 'react-router'
import { PublicRoute, AuthedRoute } from 'components/route'
import { connect } from 'react-redux'
import Fullscreen from 'react-full-screen'
import { Root as RootStyle } from 'style'
import PropTypes from 'prop-types'
import { user as userDuck, config as configDuck } from 'ducks'
import Error from './404'
import Auth from './auth'
import Signin from './signin'
import AuthHome from './authHome'

class rootView extends React.Component {
  static propTypes = {
    user: PropTypes.bool.isRequired,
    fullScreen: PropTypes.bool.isRequired,
    actionLoadUser: PropTypes.func.isRequired,
    actionReciveUser: PropTypes.func.isRequired,
    setFullScreen: PropTypes.func.isRequired,
  }

  componentDidMount() {}

  componentWillUnmount() {}

  render() {
    const { user, fullScreen, setFullScreen } = this.props
    return (
      <Switch>
        <PublicRoute exact path="/sign-in" component={Signin} />
        <PublicRoute exact path="/auth" component={Auth} />
        <Route exact path="/error" component={Error} />
        <AuthedRoute exact={false} path="/" component={AuthHome} />
        <Redirect path="*" to="/error" />
      </Switch>
    )
  }
}

const mapStateToProps = state => ({
  fullScreen: configDuck.selectors.fullScreen(state),
})

const mapDispatchToProps = {
  ...userDuck.creators,
  ...configDuck.creators,
}

export default withRouter(
  connect(
    mapStateToProps,
    mapDispatchToProps,
  )(rootView),
)
